AK: Relax ensure_capacity assertion to allow allocator-rounded capacity#8897
AK: Relax ensure_capacity assertion to allow allocator-rounded capacity#8897officialasishkumar wants to merge 1 commit intoLadybirdBrowser:masterfrom
Conversation
|
Hello! One or more of the commit messages in this PR do not match the Ladybird code submission policy, please check the |
The ensure_capacity contract guarantees that the resulting capacity is at least the requested value, not exactly equal to it. Allocators such as mimalloc may round up the allocation to an internally efficient size (via mi_good_size), so the actual capacity can exceed the requested amount when building with BUILD_PRESET=Debug. Replace EXPECT_EQ with EXPECT_GE in the json_array_ensure_capacity test to reflect the weaker, correct postcondition. Fixes LadybirdBrowser#8876.
b3fcabc to
4e63abb
Compare
|
Hi @officialasishkumar, its a good idea, but did you try the fix locally? I don't think EXPECT_GE is available, which would be available with gtest, but this is not gtest. Have a look at: and for the BigInt some additional macros are created which could give you ideas. See |
|
@officialasishkumar Between this and other changes that were submitted and don't even build, it is quite difficult to trust any of the 10 PRs that you opened in quick succession. Do not submit PRs from AI that you have not tested and thought through yourself. See here: https://github.com/LadybirdBrowser/ladybird/blob/master/CONTRIBUTING.md#on-usage-of-ai-and-llms |
The
ensure_capacityfunction guarantees that the resulting capacity isat least the requested value; it does not guarantee an exact match. The
underlying
try_ensure_capacityimplementation asks the allocator for a"good" size via
kmalloc_good_size, which maps tomi_good_sizewhenmimalloc is in use. In debug builds mimalloc may return a size larger than
requested, causing the raw element count to exceed
new_capacity.The
json_array_ensure_capacitytest checked for exact equality (EXPECT_EQ)which fails in debug builds with mimalloc. Switch to
EXPECT_GEto testonly the weaker, actually-guaranteed postcondition.
Fixes #8876.